package what.basic.basiccomponent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Jcardlayout {
	private JPanel pane=null,p=null;
	private CardLayout card=null;
	private JButton btn1=null,btn2=null;
	private JButton b1=null,b2=null,b3=null;
	private JPanel p1=null,p2=null,p3=null;
	Jcardlayout(){
//		super();
		JFrame jf =new JFrame();
		try{
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		}
		catch(Exception ex){
			ex.printStackTrace();
		}
		card=new CardLayout(5,5);
		pane=new JPanel(card);
		p=new JPanel();
		btn1=new JButton("< ");
		btn2=new JButton(" >");
		b1=new JButton("1");
		b2=new JButton("2");
		b3=new JButton("3");
		b1.setMargin(new Insets(2,2,2,2));
		b2.setMargin(new Insets(2,2,2,2));
		b3.setMargin(new Insets(2,2,2,2));
		p.add(btn1);
		p.add(b1);
		p.add(b2);
		p.add(b3);
		p.add(btn2);
		p1=new JPanel();
		p2=new JPanel();
		p3=new JPanel();
		p1.setBackground(Color.RED);
		p2.setBackground(Color.BLUE);
		p3.setBackground(Color.GREEN);
		p1.add(new JLabel("JPanel_1"));
		p2.add(new JLabel("JPanel_2"));
		p3.add(new JLabel("JPanel_3"));
		pane.add(p1,"p1");
		pane.add(p2,"p2");
		pane.add(p3,"p3");
		btn1.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				card.previous(pane);
			}
		});
		btn2.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				card.next(pane);
			}
		});
		b1.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				card.show(pane,"p1");
			}
		});
		b2.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				card.show(pane,"p2");
			}
		});
		b3.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				card.show(pane,"p3");
			}
		});
		jf.getContentPane().add(pane);
		jf.getContentPane().add(p, BorderLayout.SOUTH);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.setSize(new Dimension(300,200));
		jf.setVisible(true);
	}
	public static void main(String[] args) {
		new Jcardlayout();
	}

}
